/*
 * Created by: 	Zhaoningbo
 * at:			2011-8-29 - 上午10:50:59
 * blog:		(http://zhaoningbo.iteye.com/)
 */
package com.gc.action;

import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class LogProxy implements InvocationHandler, Serializable {

    private static final long serialVersionUID = 6082521213674400956L;
    private org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
            .getLog(this.getClass().getName());

    private Object delegate;

    public Object bind(Object delegate) {
        this.delegate = delegate;
        return Proxy.newProxyInstance(delegate.getClass().getClassLoader(),
                delegate.getClass().getInterfaces(), this);
    }

    public Object invoke(Object proxy, Method method, Object[] args)
            throws Throwable {

        Object result = null;
        
        log.info("start");
        result = method.invoke(this.delegate, args);
        log.info("end");
        
        return result;
    }

}
